﻿@using Microsoft.AspNetCore.Localization;
@using Microsoft.AspNetCore.Mvc.Localization;
@using Microsoft.Extensions.Options;
@{
    ViewData["Title"] = "Home Page";
}


@inject IViewLocalizer localizer
@inject IOptions<RequestLocalizationOptions> localOptions

@{
    var requestCulture = Context.Features.Get<IRequestCultureFeature>();
    var cultureItems = localOptions.Value.SupportedUICultures
        .Select(c => new SelectListItem { Value = c.Name, Text = c.DisplayName })
        .ToList();
}
<script>
    function SetCulture(selectedValue) {
        var url = window.location.href.split('?')[0];
        var culture = "?culture=" + selectedValue + "&ui-culture=" + selectedValue;
        window.location.href = url + culture;
    }
</script>

<label>Language:</label>
<select onchange="SetCulture(this.value)" asp-for="@requestCulture.RequestCulture.UICulture.Name" asp-items="cultureItems">
</select>

<div>
    @localizer["hello world"]
</div>
